package com.xf.oschina.dao;

import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;

import com.xf.oschina.module.book.domain.Book.ImagesBean;
import com.xf.oschina.module.book.domain.Book.ImagesBeanConverter;
import com.xf.oschina.module.book.domain.Book.RatingBean;
import com.xf.oschina.module.book.domain.Book.RatingBeanConverter;
import com.xf.oschina.module.book.domain.Book.SeriesBean;
import com.xf.oschina.module.book.domain.Book.SeriesBeanConverter;
import com.xf.oschina.module.book.domain.Book.StringConverter;
import java.util.List;

import com.xf.oschina.module.book.domain.Book;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "BOOK".
*/
public class BookDao extends AbstractDao<Book, String> {

    public static final String TABLENAME = "BOOK";

    /**
     * Properties of entity Book.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Rating = new Property(0, String.class, "rating", false, "RATING");
        public final static Property Subtitle = new Property(1, String.class, "subtitle", false, "SUBTITLE");
        public final static Property Pubdate = new Property(2, String.class, "pubdate", false, "PUBDATE");
        public final static Property Origin_title = new Property(3, String.class, "origin_title", false, "ORIGIN_TITLE");
        public final static Property Image = new Property(4, String.class, "image", false, "IMAGE");
        public final static Property Binding = new Property(5, String.class, "binding", false, "BINDING");
        public final static Property Catalog = new Property(6, String.class, "catalog", false, "CATALOG");
        public final static Property Pages = new Property(7, String.class, "pages", false, "PAGES");
        public final static Property Images = new Property(8, String.class, "images", false, "IMAGES");
        public final static Property Alt = new Property(9, String.class, "alt", false, "ALT");
        public final static Property Id = new Property(10, String.class, "id", true, "ID");
        public final static Property Publisher = new Property(11, String.class, "publisher", false, "PUBLISHER");
        public final static Property Isbn10 = new Property(12, String.class, "isbn10", false, "ISBN10");
        public final static Property Isbn13 = new Property(13, String.class, "isbn13", false, "ISBN13");
        public final static Property Title = new Property(14, String.class, "title", false, "TITLE");
        public final static Property Url = new Property(15, String.class, "url", false, "URL");
        public final static Property Alt_title = new Property(16, String.class, "alt_title", false, "ALT_TITLE");
        public final static Property Author_intro = new Property(17, String.class, "author_intro", false, "AUTHOR_INTRO");
        public final static Property Summary = new Property(18, String.class, "summary", false, "SUMMARY");
        public final static Property Tag = new Property(19, String.class, "tag", false, "TAG");
        public final static Property Series = new Property(20, String.class, "series", false, "SERIES");
        public final static Property Price = new Property(21, String.class, "price", false, "PRICE");
        public final static Property Author = new Property(22, String.class, "author", false, "AUTHOR");
        public final static Property Translator = new Property(23, String.class, "translator", false, "TRANSLATOR");
    }

    private final RatingBeanConverter ratingConverter = new RatingBeanConverter();
    private final ImagesBeanConverter imagesConverter = new ImagesBeanConverter();
    private final SeriesBeanConverter seriesConverter = new SeriesBeanConverter();
    private final StringConverter authorConverter = new StringConverter();
    private final StringConverter translatorConverter = new StringConverter();

    public BookDao(DaoConfig config) {
        super(config);
    }
    
    public BookDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"BOOK\" (" + //
                "\"RATING\" TEXT," + // 0: rating
                "\"SUBTITLE\" TEXT," + // 1: subtitle
                "\"PUBDATE\" TEXT," + // 2: pubdate
                "\"ORIGIN_TITLE\" TEXT," + // 3: origin_title
                "\"IMAGE\" TEXT," + // 4: image
                "\"BINDING\" TEXT," + // 5: binding
                "\"CATALOG\" TEXT," + // 6: catalog
                "\"PAGES\" TEXT," + // 7: pages
                "\"IMAGES\" TEXT," + // 8: images
                "\"ALT\" TEXT," + // 9: alt
                "\"ID\" TEXT PRIMARY KEY NOT NULL ," + // 10: id
                "\"PUBLISHER\" TEXT," + // 11: publisher
                "\"ISBN10\" TEXT," + // 12: isbn10
                "\"ISBN13\" TEXT," + // 13: isbn13
                "\"TITLE\" TEXT," + // 14: title
                "\"URL\" TEXT," + // 15: url
                "\"ALT_TITLE\" TEXT," + // 16: alt_title
                "\"AUTHOR_INTRO\" TEXT," + // 17: author_intro
                "\"SUMMARY\" TEXT," + // 18: summary
                "\"TAG\" TEXT," + // 19: tag
                "\"SERIES\" TEXT," + // 20: series
                "\"PRICE\" TEXT," + // 21: price
                "\"AUTHOR\" TEXT," + // 22: author
                "\"TRANSLATOR\" TEXT);"); // 23: translator
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"BOOK\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, Book entity) {
        stmt.clearBindings();
 
        RatingBean rating = entity.getRating();
        if (rating != null) {
            stmt.bindString(1, ratingConverter.convertToDatabaseValue(rating));
        }
 
        String subtitle = entity.getSubtitle();
        if (subtitle != null) {
            stmt.bindString(2, subtitle);
        }
 
        String pubdate = entity.getPubdate();
        if (pubdate != null) {
            stmt.bindString(3, pubdate);
        }
 
        String origin_title = entity.getOrigin_title();
        if (origin_title != null) {
            stmt.bindString(4, origin_title);
        }
 
        String image = entity.getImage();
        if (image != null) {
            stmt.bindString(5, image);
        }
 
        String binding = entity.getBinding();
        if (binding != null) {
            stmt.bindString(6, binding);
        }
 
        String catalog = entity.getCatalog();
        if (catalog != null) {
            stmt.bindString(7, catalog);
        }
 
        String pages = entity.getPages();
        if (pages != null) {
            stmt.bindString(8, pages);
        }
 
        ImagesBean images = entity.getImages();
        if (images != null) {
            stmt.bindString(9, imagesConverter.convertToDatabaseValue(images));
        }
 
        String alt = entity.getAlt();
        if (alt != null) {
            stmt.bindString(10, alt);
        }
 
        String id = entity.getId();
        if (id != null) {
            stmt.bindString(11, id);
        }
 
        String publisher = entity.getPublisher();
        if (publisher != null) {
            stmt.bindString(12, publisher);
        }
 
        String isbn10 = entity.getIsbn10();
        if (isbn10 != null) {
            stmt.bindString(13, isbn10);
        }
 
        String isbn13 = entity.getIsbn13();
        if (isbn13 != null) {
            stmt.bindString(14, isbn13);
        }
 
        String title = entity.getTitle();
        if (title != null) {
            stmt.bindString(15, title);
        }
 
        String url = entity.getUrl();
        if (url != null) {
            stmt.bindString(16, url);
        }
 
        String alt_title = entity.getAlt_title();
        if (alt_title != null) {
            stmt.bindString(17, alt_title);
        }
 
        String author_intro = entity.getAuthor_intro();
        if (author_intro != null) {
            stmt.bindString(18, author_intro);
        }
 
        String summary = entity.getSummary();
        if (summary != null) {
            stmt.bindString(19, summary);
        }
 
        String tag = entity.getTag();
        if (tag != null) {
            stmt.bindString(20, tag);
        }
 
        SeriesBean series = entity.getSeries();
        if (series != null) {
            stmt.bindString(21, seriesConverter.convertToDatabaseValue(series));
        }
 
        String price = entity.getPrice();
        if (price != null) {
            stmt.bindString(22, price);
        }
 
        List author = entity.getAuthor();
        if (author != null) {
            stmt.bindString(23, authorConverter.convertToDatabaseValue(author));
        }
 
        List translator = entity.getTranslator();
        if (translator != null) {
            stmt.bindString(24, translatorConverter.convertToDatabaseValue(translator));
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, Book entity) {
        stmt.clearBindings();
 
        RatingBean rating = entity.getRating();
        if (rating != null) {
            stmt.bindString(1, ratingConverter.convertToDatabaseValue(rating));
        }
 
        String subtitle = entity.getSubtitle();
        if (subtitle != null) {
            stmt.bindString(2, subtitle);
        }
 
        String pubdate = entity.getPubdate();
        if (pubdate != null) {
            stmt.bindString(3, pubdate);
        }
 
        String origin_title = entity.getOrigin_title();
        if (origin_title != null) {
            stmt.bindString(4, origin_title);
        }
 
        String image = entity.getImage();
        if (image != null) {
            stmt.bindString(5, image);
        }
 
        String binding = entity.getBinding();
        if (binding != null) {
            stmt.bindString(6, binding);
        }
 
        String catalog = entity.getCatalog();
        if (catalog != null) {
            stmt.bindString(7, catalog);
        }
 
        String pages = entity.getPages();
        if (pages != null) {
            stmt.bindString(8, pages);
        }
 
        ImagesBean images = entity.getImages();
        if (images != null) {
            stmt.bindString(9, imagesConverter.convertToDatabaseValue(images));
        }
 
        String alt = entity.getAlt();
        if (alt != null) {
            stmt.bindString(10, alt);
        }
 
        String id = entity.getId();
        if (id != null) {
            stmt.bindString(11, id);
        }
 
        String publisher = entity.getPublisher();
        if (publisher != null) {
            stmt.bindString(12, publisher);
        }
 
        String isbn10 = entity.getIsbn10();
        if (isbn10 != null) {
            stmt.bindString(13, isbn10);
        }
 
        String isbn13 = entity.getIsbn13();
        if (isbn13 != null) {
            stmt.bindString(14, isbn13);
        }
 
        String title = entity.getTitle();
        if (title != null) {
            stmt.bindString(15, title);
        }
 
        String url = entity.getUrl();
        if (url != null) {
            stmt.bindString(16, url);
        }
 
        String alt_title = entity.getAlt_title();
        if (alt_title != null) {
            stmt.bindString(17, alt_title);
        }
 
        String author_intro = entity.getAuthor_intro();
        if (author_intro != null) {
            stmt.bindString(18, author_intro);
        }
 
        String summary = entity.getSummary();
        if (summary != null) {
            stmt.bindString(19, summary);
        }
 
        String tag = entity.getTag();
        if (tag != null) {
            stmt.bindString(20, tag);
        }
 
        SeriesBean series = entity.getSeries();
        if (series != null) {
            stmt.bindString(21, seriesConverter.convertToDatabaseValue(series));
        }
 
        String price = entity.getPrice();
        if (price != null) {
            stmt.bindString(22, price);
        }
 
        List author = entity.getAuthor();
        if (author != null) {
            stmt.bindString(23, authorConverter.convertToDatabaseValue(author));
        }
 
        List translator = entity.getTranslator();
        if (translator != null) {
            stmt.bindString(24, translatorConverter.convertToDatabaseValue(translator));
        }
    }

    @Override
    public String readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10);
    }    

    @Override
    public Book readEntity(Cursor cursor, int offset) {
        Book entity = new Book( //
            cursor.isNull(offset + 0) ? null : ratingConverter.convertToEntityProperty(cursor.getString(offset + 0)), // rating
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // subtitle
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // pubdate
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // origin_title
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // image
            cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // binding
            cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // catalog
            cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // pages
            cursor.isNull(offset + 8) ? null : imagesConverter.convertToEntityProperty(cursor.getString(offset + 8)), // images
            cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // alt
            cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // id
            cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11), // publisher
            cursor.isNull(offset + 12) ? null : cursor.getString(offset + 12), // isbn10
            cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13), // isbn13
            cursor.isNull(offset + 14) ? null : cursor.getString(offset + 14), // title
            cursor.isNull(offset + 15) ? null : cursor.getString(offset + 15), // url
            cursor.isNull(offset + 16) ? null : cursor.getString(offset + 16), // alt_title
            cursor.isNull(offset + 17) ? null : cursor.getString(offset + 17), // author_intro
            cursor.isNull(offset + 18) ? null : cursor.getString(offset + 18), // summary
            cursor.isNull(offset + 19) ? null : cursor.getString(offset + 19), // tag
            cursor.isNull(offset + 20) ? null : seriesConverter.convertToEntityProperty(cursor.getString(offset + 20)), // series
            cursor.isNull(offset + 21) ? null : cursor.getString(offset + 21), // price
            cursor.isNull(offset + 22) ? null : authorConverter.convertToEntityProperty(cursor.getString(offset + 22)), // author
            cursor.isNull(offset + 23) ? null : translatorConverter.convertToEntityProperty(cursor.getString(offset + 23)) // translator
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, Book entity, int offset) {
        entity.setRating(cursor.isNull(offset + 0) ? null : ratingConverter.convertToEntityProperty(cursor.getString(offset + 0)));
        entity.setSubtitle(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setPubdate(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setOrigin_title(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setImage(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
        entity.setBinding(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
        entity.setCatalog(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
        entity.setPages(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7));
        entity.setImages(cursor.isNull(offset + 8) ? null : imagesConverter.convertToEntityProperty(cursor.getString(offset + 8)));
        entity.setAlt(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9));
        entity.setId(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10));
        entity.setPublisher(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11));
        entity.setIsbn10(cursor.isNull(offset + 12) ? null : cursor.getString(offset + 12));
        entity.setIsbn13(cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13));
        entity.setTitle(cursor.isNull(offset + 14) ? null : cursor.getString(offset + 14));
        entity.setUrl(cursor.isNull(offset + 15) ? null : cursor.getString(offset + 15));
        entity.setAlt_title(cursor.isNull(offset + 16) ? null : cursor.getString(offset + 16));
        entity.setAuthor_intro(cursor.isNull(offset + 17) ? null : cursor.getString(offset + 17));
        entity.setSummary(cursor.isNull(offset + 18) ? null : cursor.getString(offset + 18));
        entity.setTag(cursor.isNull(offset + 19) ? null : cursor.getString(offset + 19));
        entity.setSeries(cursor.isNull(offset + 20) ? null : seriesConverter.convertToEntityProperty(cursor.getString(offset + 20)));
        entity.setPrice(cursor.isNull(offset + 21) ? null : cursor.getString(offset + 21));
        entity.setAuthor(cursor.isNull(offset + 22) ? null : authorConverter.convertToEntityProperty(cursor.getString(offset + 22)));
        entity.setTranslator(cursor.isNull(offset + 23) ? null : translatorConverter.convertToEntityProperty(cursor.getString(offset + 23)));
     }
    
    @Override
    protected final String updateKeyAfterInsert(Book entity, long rowId) {
        return entity.getId();
    }
    
    @Override
    public String getKey(Book entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(Book entity) {
        return entity.getId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
}
